<template>
  <div class="bigbox">
      <div class="top">
          <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="名称">
    <el-input v-model="form.name" placeholder="专题名称"></el-input>
    <el-button type="primary" @click="searchFn">查询</el-button>
      <el-button type="primary" @click="addFn">添加</el-button>
  </el-form-item>
    </el-form>
      </div>

      <div class="bom">
          <el-table
    :data="getTopicLists"
    border
    style="width: 100%">
    <el-table-column
      prop="id"
      label="ID">
    </el-table-column>
    <el-table-column
      prop="title"
      label="主标题">
    </el-table-column>
    <el-table-column
      prop="price_info"
      label="起步价格">
    </el-table-column>
    <el-table-column
      prop="is_show"
      label="显示">
      <template slot-scope="scope">
              {{
                scope.row.is_show === 1 ? "是" : "否"
              }}
          </template>
    </el-table-column>
    <el-table-column
      prop="caozuo"
      label="操作">
      <template slot-scope="scope">
        <el-button
        type="primary"
          @click="bianjiFn(scope.row.id)">编辑</el-button>
      </template>
    </el-table-column>
  </el-table>
      </div>

      <div class="last">
          <div class="block">
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="100"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.count">
    </el-pagination>
  </div>
      </div>
  </div>
</template>

<script>
import {getTopicLists} from '../../request/httpApi'
export default {
    data(){
        return{
            form:{
                name:''
            },
            getTopicLists:[],   // 专题页渲染
            page:1, // 页面
            size:10, // 页面显示个数
            count:0, // 总数
        }
    },

    created(){
        this.fenzhuang()
    },
     methods: {
      handleSizeChange(val) {
        // console.log(`每页 ${val} 条`);
        this.size = `${val}`
        this.fenzhuang()
      },
      handleCurrentChange(val) {
        // console.log(`当前页: ${val}`);
        this.page = `${val}`
        this.fenzhuang()
      },

    //   封装首页数据
    fenzhuang(){
        getTopicLists({
            page:this.page,
            size:this.size,
            name:this.form.name
        }).then((res)=>{
            console.log(res);
            this.getTopicLists = res.data.data
            this.count = res.data.count
            console.log(this.getTopicLists);
        })
    },
    
    // 查询功能
    searchFn(){
        this.fenzhuang()
    },

    // 添加跳转页面
    addFn(){
        this.$router.push('/addtopic')
    },

    // 编辑跳转功能
    bianjiFn(e){
      this.$router.push(`/edittopic/${e}`)
    }
    },
}
</script>

<style lang="less" scoped>
.bigbox{
    padding-top: 20px;
  padding-bottom: 160px;
  background-color: #fff;
  .top{
      padding-bottom: 20px;
    .el-input {
      width: 210px;
      margin-right: 15px;
      /deep/ .el-input__inner {
        height: 36px;
        line-height: 36px;
        border-radius: 5px;
      }
    }
  }
  .last {
    padding-top: 20px;
    position: absolute;
    right: 0;
  }
}
</style>